package com.dundun.pattern.flyweight;

import java.util.HashMap;
import java.util.Map;

public class BigCharFactory {

    private Map<Character, BigChar> pool = new HashMap<>();
    private static BigCharFactory factory = new BigCharFactory();
    private BigCharFactory() {}

    public static BigCharFactory getInstance() {
        return factory;
    }

    public synchronized BigChar getBigChar(char charname) {
        BigChar bc = pool.get(charname);
        if(bc == null) {
            bc = new BigChar(charname);
            pool.put(charname, bc);
        }
        return bc;
    }
}
